package by.grsu.coctails.adapter;

import java.util.List;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import by.grsu.coctails.R;
import by.grsu.coctails.common.utils.ImageManager;
import by.grsu.coctails.model.Ingredient;

public class CompositionAdapter extends AbstractAdapter<Ingredient> {

	public CompositionAdapter(Context c, int pItemResource,
			List<Ingredient> pList) {
		super(c, pItemResource, pList);
	}

	@Override
	public void init(View convertView, Ingredient item) {
		ImageView image = (ImageView) convertView.findViewById(R.id.image);
		getImageLoader().bind(this, image, ImageManager.HTTP + item.getImage());

		TextView name = (TextView) convertView.findViewById(R.id.name);
		name.setText(item.getName());

		TextView count = (TextView) convertView.findViewById(R.id.count);
		StringBuilder countBuilder = new StringBuilder();
		if (item.getCount() != null && !item.getCount().equals("null")) {
			countBuilder.append(item.getCount());
			countBuilder.append(" ");
		}
		if (item.getAmountValue() != null
				&& !item.getAmountValue().equals("null")) {
			countBuilder.append(item.getAmountValue());
		}
		count.setText(countBuilder.toString());

		LinearLayout compositionWithoutImage = (LinearLayout) convertView
				.findViewById(R.id.composition_without_image);

		if (item.isHaved() == 1) {
			compositionWithoutImage.setBackgroundResource(R.color.white);
		} else {
			compositionWithoutImage.setBackgroundResource(R.color.grey);
		}

	}

}
